// 3.2  SchedulingServiceImpl.java
package com.neuedu.his.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.neuedu.his.controller.ScheduleController.GenReq;
import com.neuedu.his.mapper.SchedulingMapper;
import com.neuedu.his.po.Scheduling;
import com.neuedu.his.service.SchedulingService;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

/** 简易实现：示范用，按 ruleId 直接落表，无校验冲突 */
@Service
public class SchedulingServiceImpl                // ✔ 类名 = 文件名
        extends ServiceImpl<SchedulingMapper, Scheduling>
        implements SchedulingService {

    @Override
    public boolean generateByRules(GenReq req) {

        LocalDate cur = req.start();
        List<Scheduling> batch = new ArrayList<>();

        while (!cur.isAfter(req.end())) {
            for (Integer ruleId : req.ruleIds()) {
                Scheduling s = new Scheduling();
                s.setScheddate(java.sql.Date.valueOf(cur));
                s.setRuleid(ruleId);
                s.setDeptid(0);   // TODO: 根据规则反填
                s.setUserid(0);   // TODO
                s.setNoon("上午"); // TODO
                s.setDelmark(1);
                batch.add(s);
            }
            cur = cur.plusDays(1);
        }
        return this.saveBatch(batch);
    }
}
